home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 051-075 / 074 / less / ttyin.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  897b  |  58 lines

  1. /*
  2.  * Routines dealing with getting input from the keyboard (i.e. from the user).
  3.  */
  4.  
  5. #include "less.h"
  6.  
  7. /*
  8.  * The boolean "reading" is set true or false according to whether
  9.  * we are currently reading from the keyboard.
  10.  * This information is used by the signal handling stuff in signal.c.
  11.  * {{ There are probably some race conditions here
  12.  *    involving the variable "reading". }}
  13.  */
  14. public int reading;
  15.  
  16. #ifdef amiga
  17. extern struct FileHandle *tty;
  18. #else
  19. static int tty;
  20. #endif
  21.  
  22. /*
  23.  * Open keyboard for input.
  24.  * (Just use file descriptor 2.)
  25.  */
  26.     public void
  27. open_getc()
  28. {
  29. #ifdef amiga
  30.     ttopen();
  31. #else
  32.     tty = 2;
  33. #endif
  34. }
  35.  
  36. /*
  37.  * Get a character from the keyboard.
  38.  */
  39.     public int
  40. getc()
  41. {
  42.     char c;
  43.     int result;
  44.  
  45.     reading = 1;
  46.     do
  47.     {
  48.         flush();
  49. #ifdef amiga
  50.         result = Read(tty, &c, 1L);
  51. #else
  52.         result = read(tty, &c, 1);
  53. #endif
  54.     } while (result != 1);
  55.     reading = 0;
  56.     return (c & 0177);
  57. }
  58.